package com.sunfeng.netty.heima.day01.buffer;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

import static com.sunfeng.netty.heima.utils.ByteBufferUtil.debugAll;

/**
 * @ClassName ScatteringReadTest
 * @Description TODO
 * @Author 孙峰
 * @Date 2022/10/21 16:11
 */
public class ScatteringReadTest {
    public static void main(String[] args) {
        try (RandomAccessFile file = new RandomAccessFile("3parts.txt", "r")) {
            FileChannel channel = file.getChannel();
            ByteBuffer buffer1 = ByteBuffer.allocate(3);
            ByteBuffer buffer2 = ByteBuffer.allocate(3);
            ByteBuffer buffer3 = ByteBuffer.allocate(5);

            channel.read(new ByteBuffer[]{buffer1,buffer2,buffer3});
            buffer1.flip();
            buffer2.flip();
            buffer3.flip();
            debugAll(buffer1);
            debugAll(buffer2);
            debugAll(buffer3);


        } catch (Exception e) {

        }
    }
}
